
import os
import re

def coetrans(rfp):
    fo = open(rfp, "r+")
    rfw = rfp+".coe"
    fw = open(rfw, "w+")
    fw.write("memory_initialization_radix = 16;\nmemory_initialization_vector = \n")
    
    inst = fo.readline()
    while inst != "" :
        fw.write(inst[0:-1].upper())
        inst = fo.readline()
        if inst != "":
            fw.write(", ")
    fw.write(";")

# fo.close()
# pattern=r"123"
# for fn in os.listdir('./'):  
#     if ".data" in fn:
#         fp = './'+fn
#         coetrans(fp)
# for fn in os.listdir('./testbench'):  
#     if fn.endswith(".data"):
#         fp = './testbench/'+fn
#         coetrans(fp)


coetrans('./inst_rom.data')


